package first.c01;

import java.util.ArrayList;
import java.util.List;

public class Customer {

	private String name;
	private List<Rental> rentals = new ArrayList<Rental>();

	public Customer(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void addRental(Rental rental) {
		rentals.add(rental);
	}

	public String htmlStatement() {

		String result = "<H1>Rentals for <EM>" + getName() + "</EM></ H1><P>\n";
		for (Rental rental : rentals) {
			result += rental.getMovie().getTitle() + ": "
					+ String.valueOf(rental.getCharge()) + "<BR>\n";
		}
		// add footer lines
		result += "<P>You owe <EM>" + String.valueOf(getTotalCharge())
				+ "</EM><P>\n";
		result += "On this rental you earned <EM>"
				+ String.valueOf(getTotalFrequentRenterPoints())
				+ "</EM> frequent renter points<P>";
		return result;
	}

	public String statement() {

		String result = "Rental Record for " + getName() + "\n";

		for (Rental rental : rentals) {
			// show figures for this rental（显示此笔租借记录）
			result += "\t" + rental.getMovie().getTitle() + "\t"
					+ String.valueOf(rental.getCharge()) + "\n";
		}
		// add footer lines（结尾打印）
		result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
		result += "You earned "
				+ String.valueOf(getTotalFrequentRenterPoints())
				+ " frequent renter points";

		return result;
	}

	public double getTotalCharge() {
		double result = 0;

		for (Rental rental : rentals) {

			result += rental.getCharge();
		}
		return result;
	}

	public int getTotalFrequentRenterPoints() {
		int result = 0;

		for (Rental rental : rentals) {
			result += rental.getFrequentRenterPoints();
		}

		return result;
	}

}
